<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>找回密码</title>
  <meta name="renderer" content="webkit"/>
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <script src="__STATIC__/plugs/jquery/jquery.min.js"></script>
</head>
<body>
手机：<input type="text" name="mobile" value=""><br/>
验证码：<input type="text" name="verify_code" value=""><br/>
<input type="button"  value="点击获取验证码" onclick="get_verify_code()"><br/>
密码：<input type="password" name="password" value=""><br/>
确认密码：<input type="password" name="repassword" value=""><br/>
<input type="button"  value="提交" onclick="save()"><br/>
</body>
</html>
<script>
  /**
   * 	获取短信验证码
   * 	@param  $mobile  绑定手机
   */
  function get_verify_code(){
      var mobile = $('input[name=mobile]').val();
      if(mobile == ''){
          alert('请输入手机号');
          return false;
      }
      $.post("{:url('Outlo/get_verify_code')}",
          {mobile:mobile},
          function(data){
              if(data.code == 1){
//                  layer.msg(data.msg, {
//                      icon: 1,
//                      time: 1000 //2秒关闭（如果不配置，默认是3秒）
//                  }, function () {
//
//                  });
              }else{
//                  layer.msg(data.msg, {
//                      icon: 2,
//                      time: 1000 //2秒关闭（如果不配置，默认是3秒）
//                  }, function () {
//
//                  });
              }
          }
      );
  }
  /**
   * 保存数据
   */
  function save(){
      var reg = /^[0-9a-zA-Z_]{6,16}$/;
      var password = $('input[name=password]').val();
      var repassword = $('input[name=repassword]').val();
      var mobile = $('input[name=mobile]').val();
      var verify_code = $('input[name=verify_code]').val();
      if(!reg.test(password)){
          alert('密码格式不正确，只能是字母数字下划线6~16位组合');
          return false;
      }
      if(password != repassword){
          alert('两次密码输入不一致，请重新填写');
          return false;
      }
      if(mobile == ''){
          alert('请输入手机');
          return false;
      }
      if(verify_code == ''){
          alert('请输入验证码');
          return false;
      }

      $.post("{:url('Outlo/find_password')}",
          {mobile:mobile,password:password,repassword:repassword,verify_code:verify_code},
          function(data){
              if(data.code == 1){
                  alert('密码重置成功');
                  window.location.href = "{:url('Index/index')}";
              }else{
                  alert('密码重置失败，请重试');
              }
          }
      );
  }
</script>